//统一管理咱们项目用户相关的接口
import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import {
  AddUserParams,
  UpdateUserInfoParams,
  UserAvatarOrSignParams,
  UserInfoPageParams,
  UserInfoRes,
  UserPageRes,
  UserRolesParams,
} from './type'
import qs from 'qs'
// 项目用户相关的请求地址

enum User_API {
  DELETE_USER_BYID = '/teaching_system/user/deleted/{id}',
  DISABLE_USER_BYID = '/teaching_system/user/disabled/{id}',
  GET_OR_DELETE_MY_USERINFO = '/teaching_system/user/me',
  GET_OR_POST_USERINFO_PAGE = '/teaching_system/user/more',
  POST_OR_PUT_USERINFO = '/teaching_system/user/one',
  GET_OTHER_USERINFO = '/teaching_system/user/other/{username}',
  POST_OR_DELETE_USER_ROLE = '/teaching_system/user/role',
  PUT_RESET_PWD = '/teaching_system/user/reset/{id}',
  PUT_USER_AVATAR = '/teaching_system/user/avatar',
  PUT_USER_SIGN = '/teaching_system/user/sign',
}

/**
 * 恢复用户
 * @param {string} id
 * @returns
 */
export const reqRecoverUser = (id: number) =>
  request.put<any, AxiosResponse<any>>(
    User_API.DELETE_USER_BYID.replace('{id}', id.toString()),
  )

/**
 * 注销用户（管理员）
 * @param {string} id
 * @returns
 */
export const reqDeleteUser = (id: number) =>
  request.delete<any, AxiosResponse<any>>(
    User_API.DELETE_USER_BYID.replace('{id}', id.toString()),
  )

/**
 * 取消禁用用户（管理员）
 * @param {string} id
 * @returns
 */
export const reqUnDisableUser = (id: number) =>
  request.put<any, AxiosResponse<any>>(
    User_API.DISABLE_USER_BYID.replace('{id}', id.toString()),
  )

/**
 * 禁用用户（管理员）
 * @param {string} id
 * @returns
 */
export const reqDisableUser = (id: number) =>
  request.delete<any, AxiosResponse<any>>(
    User_API.DISABLE_USER_BYID.replace('{id}', id.toString()),
  )

/**
 * 获取自己的用户信息
 * @returns
 */
export const reqMyUserInfo = () =>
  request.get<any, AxiosResponse<UserInfoRes>>(
    User_API.GET_OR_DELETE_MY_USERINFO,
  )

/**
 * 自己注销用户
 * @returns
 */
export const reqDeleteUserSelf = () =>
  request.delete<any, AxiosResponse<any>>(User_API.GET_OR_DELETE_MY_USERINFO)

/**
 * 用户分页（管理员）
 * @param {string} userPageQuery
 * @returns
 */
export const reqUserInfoPage = (params: UserInfoPageParams) =>
  request.get<any, AxiosResponse<UserPageRes>>(
    User_API.GET_OR_POST_USERINFO_PAGE + '?' + qs.stringify(params),
  )

// /**
// * 批量添加用户（管理员）
// * @param {object} params 新增用户表
// * @param {string} params.username 用户名（身份ID)
// * @param {string} params.password 密码
// * @param {string} params.name 姓名
// * @param {number} params.sex 性别
// * @returns
// */
// export const reqAddUsers = (params: UserInfoPageParams) =>
//   request.get<any, AxiosResponse<any>>(
//     User_API.GET_OR_POST_USERINFO_PAGE + '?' + qs.stringify(params)
//   )

/**
 * 添加用户（管理员）
 * @param {object} params 新增用户表
 * @param {string} params.username 用户名（身份ID)
 * @param {string} params.password 密码
 * @param {string} params.name 姓名
 * @param {number} params.sex 性别
 * @returns
 */
export const reqAddUser = (params: AddUserParams) =>
  request.post<any, AxiosResponse<any>>(User_API.POST_OR_PUT_USERINFO, params)

/**
 * 修改信息
 * @param {object} params
 * @param {number} params.id 用户id
 * @param {string} params.name 姓名
 * @param {string} params.email 邮箱
 * @param {string} params.sign 签名
 * @param {number} params.sex 性别
 * @param {string} params.avatar 用户头像
 * @returns
 */
export const reqUpdateUserInfo = (params: AddUserParams) =>
  request.put<any, AxiosResponse<any>>(User_API.POST_OR_PUT_USERINFO, params)

/**
 * 重置密码（管理员）
 * @param {string} id
 * @returns
 */
export const reqResetPwd = (id: number) =>
  request.put<any, AxiosResponse<any>>(
    User_API.PUT_RESET_PWD.replace('{id}', id.toString()),
  )

/**
 * 为用户添加角色(管理员)
 * @param {object} params UserRoleForm
 * @param {array} params.roleIds
 * @param {number} params.userId
 * @returns
 */
export const reqResetUserRole = (params: UserRolesParams) =>
  request.post<any, AxiosResponse<any>>(
    User_API.POST_OR_DELETE_USER_ROLE,
    params,
  )

/**
 * 为用户删除角色(管理员)
 * @param {object} params UserRoleForm
 * @param {array} params.roleIds
 * @param {number} params.userId
 * @returns
 */
export const reqDeleteUserRole = (params: UserRolesParams) =>
  request.put<any, AxiosResponse<any>>(
    User_API.POST_OR_DELETE_USER_ROLE,
    params,
  )

/**
 * 修改头像
 * @param {string} content
 * @returns
 */
export const reqUpdateUserAvatar = (data: UserAvatarOrSignParams) =>
  request.put<any, AxiosResponse<any>>(
    User_API.PUT_USER_AVATAR + '?' + qs.stringify(data),
  )

/**
 * 修改标签
 * @param {string} content
 * @returns
 */
export const reqUpdateUserSign = (data: UserAvatarOrSignParams) =>
  request.put<any, AxiosResponse<any>>(
    User_API.PUT_USER_SIGN + '?' + qs.stringify(data),
  )
